var ArealmeSearchWidget=(function(oe){"use strict";var ae,v,Fe,M,We,Ye,Ke,Ve,be,Se,ve,se={},ie=[],Ft=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ce=Array.isArray;function O(e,t){for(var n in t)e[n]=t[n];return e}function Te(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function Wt(e,t,n){var r,a,o,s={};for(o in t)o=="key"?r=t[o]:o=="ref"?a=t[o]:s[o]=t[o];if(arguments.length>2&&(s.children=arguments.length>3?ae.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(o in e.defaultProps)s[o]===void 0&&(s[o]=e.defaultProps[o]);return le(e,s,r,a,null)}function le(e,t,n,r,a){var o={type:e,props:t,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:a??++Fe,__i:-1,__u:0};return a==null&&v.vnode!=null&&v.vnode(o),o}function B(e){return e.children}function ue(e,t){this.props=e,this.context=t}function D(e,t){if(t==null)return e.__?D(e.__,e.__i+1):null;for(var n;tt&&M.sort(Ke),e=M.shift(),t=M.length,Yt(e);de.__r=0}function Ze(e,t,n,r,a,o,s,l,u,c,h){var i,f,_,w,T,y,m,p=r&&r.__k||ie,k=t.length;for(u=Kt(n,t,p,u,k),i=0;i0?s=e.__k[o]=le(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):e.__k[o]=s,u=o+f,s.__=e,s.__b=e.__b+1,l=null,(c=s.__i=Vt(s,n,u,i))!=-1&&(i--,(l=n[c])&&(l.__u|=2)),l==null||l.__v==null?(c==-1&&(a>h?f--:au?f--:f++,s.__u|=4))):e.__k[o]=null;if(i)for(o=0;o(h?1:0)){for(a=n-1,o=n+1;a>=0||o=0?a--:o++])!=null&&(2&c.__u)==0&&l==c.key&&u==c.type)return s}return-1}function tt(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||Ft.test(t)?n:n+"px"}function he(e,t,n,r,a){var o,s;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof r=="string"&&(e.style.cssText=r=""),r)for(t in r)n&&t in n||tt(e.style,t,"");if(n)for(t in n)r&&n[t]==r[t]||tt(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")o=t!=(t=t.replace(Ve,"$1")),s=t.toLowerCase(),t=s in e||t=="onFocusOut"||t=="onFocusIn"?s.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+o]=n,n?r?n.u=r.u:(n.u=be,e.addEventListener(t,o?ve:Se,o)):e.removeEventListener(t,o?ve:Se,o);else{if(a=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function nt(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=be++;else if(t.t0?e:ce(e)?e.map(ot):O({},e)}function Xt(e,t,n,r,a,o,s,l,u){var c,h,i,f,_,w,T,y=n.props||se,m=t.props,p=t.type;if(p=="svg"?a="http://www.w3.org/2000/svg":p=="math"?a="http://www.w3.org/1998/Math/MathML":a||(a="http://www.w3.org/1999/xhtml"),o!=null){for(c=0;cr?r:a:t}async function K(e,t,n,r){const a=new AbortController,o=setTimeout(function(){a.abort()},r);try{const s=await e(t,{...n,signal:a.signal});if(!s.ok)throw mn(s.status);let l;try{l=await fn(s)}catch{throw new Error("接口返回格式错误,请稍后再试")}if(!gn(l))throw new Error("接口返回格式错误:不是 JSON 对象");return{payload:l}}catch(s){throw s instanceof Error&&s.name==="AbortError"?new Error("请求超时,请稍后重试"):s instanceof TypeError?new Error("网络异常,请检查网络后重试"):s}finally{clearTimeout(o)}}async function fn(e){return(e.headers.get("content-type")??"").includes("application/json")?e.json():e.text()}function gn(e){return e!==null&&typeof e=="object"}function mn(e){return e===400?new Error("请求参数不合法,请检查输入后重试"):e===401||e===403?new Error("当前请求未被允许,请稍后再试"):e===404?new Error("接口不可用,请联系管理员"):e>=500?new Error("服务暂时不可用,请稍后重试"):new Error(`请求失败(HTTP ${e})`)}var V,x,He,Tt,X=0,xt=[],E=v,Ct=E.__b,Lt=E.__r,Et=E.diffed,kt=E.__c,It=E.unmount,Ut=E.__;function Pe(e,t){E.__h&&E.__h(x,e,X||t),X=0;var n=x.__H||(x.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function R(e){return X=1,pn(Rt,e)}function pn(e,t,n){var r=Pe(V++,2);if(r.t=e,!r.__c&&(r.__=[Rt(void 0,t),function(l){var u=r.__N?r.__N[0]:r.__[0],c=r.t(u,l);u!==c&&(r.__N=[c,r.__[1]],r.__c.setState({}))}],r.__c=x,!x.__f)){var a=function(l,u,c){if(!r.__c.__H)return!0;var h=r.__c.__H.__.filter(function(f){return f.__c});if(h.every(function(f){return!f.__N}))return!o||o.call(this,l,u,c);var i=r.__c.props!==l;return h.some(function(f){if(f.__N){var _=f.__[0];f.__=f.__N,f.__N=void 0,_!==f.__[0]&&(i=!0)}}),o&&o.call(this,l,u,c)||i};x.__f=!0;var o=x.shouldComponentUpdate,s=x.componentWillUpdate;x.componentWillUpdate=function(l,u,c){if(this.__e){var h=o;o=void 0,a(l,u,c),o=h}s&&s.call(this,l,u,c)},x.shouldComponentUpdate=a}return r.__N||r.__}function G(e,t){var n=Pe(V++,3);!E.__s&&At(n.__H,t)&&(n.__=e,n.u=t,x.__H.__h.push(n))}function F(e){return X=5,fe(function(){return{current:e}},[])}function fe(e,t){var n=Pe(V++,7);return At(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function W(e,t){return X=8,fe(function(){return e},t)}function wn(){for(var e;e=xt.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(ge),t.__h.some(Oe),t.__h=[]}catch(n){t.__h=[],E.__e(n,e.__v)}}}E.__b=function(e){x=null,Ct&&Ct(e)},E.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ut&&Ut(e,t)},E.__r=function(e){Lt&&Lt(e),V=0;var t=(x=e.__c).__H;t&&(He===x?(t.__h=[],x.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(ge),t.__h.some(Oe),t.__h=[],V=0)),He=x},E.diffed=function(e){Et&&Et(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(xt.push(t)!==1&&Tt===E.requestAnimationFrame||((Tt=E.requestAnimationFrame)||yn)(wn)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),He=x=null},E.__c=function(e,t){t.some(function(n){try{n.__h.some(ge),n.__h=n.__h.filter(function(r){return!r.__||Oe(r)})}catch(r){t.some(function(a){a.__h&&(a.__h=[])}),t=[],E.__e(r,n.__v)}}),kt&&kt(e,t)},E.unmount=function(e){It&&It(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(r){try{ge(r)}catch(a){t=a}}),n.__H=void 0,t&&E.__e(t,n.__v))};var Nt=typeof requestAnimationFrame=="function";function yn(e){var t,n=function(){clearTimeout(r),Nt&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);Nt&&(t=requestAnimationFrame(n))}function ge(e){var t=x,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),x=t}function Oe(e){var t=x;e.__c=e.__(),x=t}function At(e,t){return!e||e.length!==t.length||t.some(function(n,r){return n!==e[r]})}function Rt(e,t){return typeof t=="function"?t(e):t}function bn(e,t){const n=new Map;for(const r of e){const a=r.contentTitle.trim();if(!a)continue;const o=`${r.contentId}\0${r.locale}`,s=n.get(o);if(!s){n.set(o,{contentId:r.contentId,contentTitle:a,locale:r.locale,hitCount:Math.max(0,r.hitCount),...r.contentUrl?{contentUrl:r.contentUrl}:{}});continue}s.hitCount+=Math.max(0,r.hitCount),!s.contentUrl&&r.contentUrl&&(s.contentUrl=r.contentUrl)}return Array.from(n.values()).sort(function(a,o){return o.hitCount!==a.hitCount?o.hitCount-a.hitCount:a.contentTitle!==o.contentTitle?a.contentTitle.localeCompare(o.contentTitle,"en"):a.locale!==o.locale?a.locale.localeCompare(o.locale,"en"):a.contentId.localeCompare(o.contentId,"en")}).slice(0,t)}function Ht(e){const t=me(e,1);return Array.from({length:t},(n,r)=>r)}function Sn(e,t){const n=me(e,1),r=Ot(t,0),a=Math.max(0,n-r);return Array.from({length:a},(o,s)=>s)}function Pt(e,t,n){const r=me(e,1),a=me(t,1),o=Ot(n,0),s=Math.max(0,r-1);return r*a+s*o}function me(e,t){const n=Math.trunc(e);return!Number.isFinite(n)||n<=0?t:n}function Ot(e,t){const n=Math.trunc(e);return!Number.isFinite(n)||n<0?t:n}const vn=" - ",Tn=" / ",$t=47;function $e(e,t={}){const n=xn(e);if(!n)return"";const r=Cn(t.maxLength),a=Ln(n),o=En(a);return kn(o,r)}function xn(e){return e.replace(/\s+/g," ").trim()}function Cn(e){return!Number.isFinite(e)||typeof e!="number"?$t:e>0?Math.floor(e):$t}function Ln(e){const t=Qt(e,Tn);return Qt(t,vn)}function Qt(e,t){const n=e.indexOf(t);return n<=0?e:e.slice(0,n).trim()}function En(e){const t=e.indexOf("?");return t<0?e.trim():e.slice(0,t+1).trim()}function kn(e,t){return e.length<=t?e:`${e.slice(0,t).trimEnd()}...`}const In=40,Un=6;function Nn(e){const t=bn(e.hotContents,e.hotLimit),n=Ht(e.hotLimit),r={minHeight:`${Pt(e.hotLimit,In,Un)}px`};return d("section",{className:"asw-panel asw-hot-panel",children:[d("h3",{children:e.t.hotContentsTitle(e.hotHours)}),d("ul",{className:"asw-list asw-hot-list",style:r,children:e.isLoadingHot?n.map(function(o){return d("li",{children:d("span",{className:"asw-suggestion asw-static-item asw-hot-skeleton","aria-hidden":"true",children:[d("span",{className:"asw-hot-title asw-skeleton-line"}),d("span",{className:"asw-hot-meta asw-skeleton-meta"})]})},`hot-placeholder-${o}`)}):t.length===0?d("li",{className:"asw-empty",children:e.t.emptyHotContents}):t.map(function(o){const s=$e(o.contentTitle)||o.contentTitle,l=Ie({siteUrl:e.siteUrl,slugOrPath:o.contentId,locale:o.locale,explicitUrl:o.contentUrl});return l?d("li",{children:d("a",{className:"asw-suggestion asw-hot-link",href:l,children:[d("span",{className:"asw-hot-title",children:s}),d("span",{className:"asw-hot-meta",children:e.t.hotContentHitCount(o.hitCount)})]})},`${o.contentId}-${o.locale}`):d("li",{children:d("span",{className:"asw-suggestion asw-static-item",children:[d("span",{className:"asw-hot-title",children:s}),d("span",{className:"asw-hot-meta",children:e.t.hotContentHitCount(o.hitCount)})]})},`${o.contentId}-${o.locale}`)})})]})}function An(e){return d("form",{className:"asw-controls",onSubmit:function(n){n.preventDefault(),e.onSearchSubmit()},children:[d("div",{className:"asw-input-wrap",children:[d("input",{ref:e.queryInputRef,className:"asw-input",type:"text",value:e.query,placeholder:e.placeholder,onInput:function(n){const r=n.currentTarget.value;e.onQueryInput(r)}}),e.query.length>0&&d("button",{className:"asw-input-clear-btn",type:"button","aria-label":e.clearQueryAriaLabel,onClick:function(){e.onClearQuery()},children:d("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:d("path",{d:"M6.3 5 5 6.3 10.7 12 5 17.7 6.3 19l5.7-5.7 5.7 5.7 1.3-1.3-5.7-5.7L19 6.3 17.7 5 12 10.7z"})})})]}),d("button",{className:"asw-button asw-search-icon-btn",type:"submit",disabled:e.isSearching,"aria-label":e.searchButtonAriaLabel,children:e.isSearching?d("svg",{"aria-hidden":"true",focusable:"false",className:"asw-spinner",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 50 50",children:d("circle",{cx:"25",cy:"25",r:"20",fill:"none",stroke:"currentColor","stroke-width":"5","stroke-dasharray":"31.4 31.4","stroke-linecap":"round",children:d("animateTransform",{attributeName:"transform",type:"rotate",from:"0 25 25",to:"360 25 25",dur:"1s",repeatCount:"indefinite"})})}):d("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 128 128",children:d("path",{"fill-rule":"nonzero",d:"M125 111 96 80q7-12 7-27c1-24-15-45-38-51S17 6 6 27C-5 49-1 75 17 91s44 18 64 4l29 30q8 6 15 0 6-8 0-14M52 88c-20 0-35-16-35-36 0-19 15-35 35-35a35 35 0 0 1 0 71"})})})]})}function Rn(e){const t=`${vt(e.apiBaseUrl)}/api/click`,n=Hn(e.payload),r=e.sendBeacon??Pn();if(r&&On(r,t,n))return;(e.fetchImpl??fetch)(t,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n),keepalive:!0}).catch(function(){})}function Hn(e){const t={query:e.query,contentId:e.contentId,contentTitle:e.contentTitle},n=e.locale?.trim();n&&(t.locale=n);const r=e.contentLocale?.trim();return r&&(t.contentLocale=r),t}function Pn(){if(!(typeof navigator>"u")&&typeof navigator.sendBeacon=="function")return navigator.sendBeacon.bind(navigator)}function On(e,t,n){try{const r=new Blob([JSON.stringify(n)],{type:"application/json; charset=utf-8"});return e(t,r)}catch{return!1}}function $n(e){return d("section",{className:"asw-panel asw-search-panel",children:[d("h3",{children:[e.t.searchTitle,e.isSearching&&d("span",{className:"asw-loading-indicator",children:"..."})]}),d("ul",{className:"asw-list",children:e.results.length===0?d("li",{className:"asw-empty",children:e.isSearching?e.t.refreshLoading:e.t.emptySearchResults}):e.results.map(function(n){const r=$e(n.title)||n.title,a=Ie({siteUrl:e.siteUrl,slugOrPath:n.slug??n.id,locale:n.locale??e.locale,explicitUrl:n.url}),o=n.slug??n.id;return a?d("li",{className:"asw-result",children:d("a",{href:a,className:"asw-result-link",onClick:function(){const l={query:e.query,contentId:o,contentTitle:n.title,locale:e.locale,contentLocale:n.locale??e.locale};Rn({apiBaseUrl:e.apiBaseUrl,payload:l})},children:[d("p",{className:"asw-title",children:r}),d("p",{className:"asw-content",children:n.content})]})},n.id):d("li",{className:"asw-result",children:[d("p",{className:"asw-title",children:r}),d("p",{className:"asw-content",children:n.content})]},n.id)})})]})}function Qn(e,t){const n=e.trim();return n?n===t.trim()?"search":"suggestion":"hot"}function Mn(e){return e.suggestionCount>0?e.suggestionCount:e.isSuggestLoading?0:1}const zn=40,Bn=6;function Dn(e){const t=Ht(e.suggestLimit),n=Mn({suggestionCount:e.suggestions.length,isSuggestLoading:e.isSuggestLoading}),r=Sn(e.suggestLimit,n),a={minHeight:`${Pt(e.suggestLimit,zn,Bn)}px`};return d("section",{className:"asw-panel",children:[d("h3",{children:[e.t.suggestTitle,e.isSuggestLoading&&d("span",{className:"asw-loading-indicator",children:"..."})]}),d("ul",{className:"asw-list asw-suggestion-list",style:a,children:e.suggestions.length===0?e.isSuggestLoading?t.map(function(s){return d("li",{children:d("span",{className:"asw-suggestion asw-static-item asw-suggestion-skeleton","aria-hidden":"true",children:d("span",{className:"asw-skeleton-line"})})},`suggest-placeholder-${s}`)}):d(B,{children:[d("li",{className:"asw-empty",children:e.t.emptySuggestions}),r.map(function(s){return d("li",{"aria-hidden":"true",children:d("span",{className:"asw-suggestion asw-static-item asw-suggestion-padding"})},`suggest-padding-empty-${s}`)})]}):d(B,{children:[e.suggestions.map(function(s){const l=`${s.id}\0${s.locale??"all"}`,u=$e(s.text)||s.text,c=Ie({siteUrl:e.siteUrl,slugOrPath:s.id,locale:s.locale??e.locale});return c?d("li",{children:d("a",{className:"asw-suggestion asw-suggestion-link",href:c,children:d("span",{className:"asw-suggestion-text",children:u})})},l):d("li",{children:d("span",{className:"asw-suggestion asw-static-item asw-suggestion-static",children:d("span",{className:"asw-suggestion-text",children:u})})},l)}),r.map(function(s){return d("li",{"aria-hidden":"true",children:d("span",{className:"asw-suggestion asw-static-item asw-suggestion-padding"})},`suggest-padding-${s}`)})]})})]})}var qn=typeof global=="object"&&global&&global.Object===Object&&global,jn=typeof self=="object"&&self&&self.Object===Object&&self,Mt=qn||jn||Function("return this")(),pe=Mt.Symbol,zt=Object.prototype,Gn=zt.hasOwnProperty,Fn=zt.toString,J=pe?pe.toStringTag:void 0;function Wn(e){var t=Gn.call(e,J),n=e[J];try{e[J]=void 0;var r=!0}catch{}var a=Fn.call(e);return r&&(t?e[J]=n:delete e[J]),a}var Yn=Object.prototype,Kn=Yn.toString;function Vn(e){return Kn.call(e)}var Xn="[object Null]",Jn="[object Undefined]",Bt=pe?pe.toStringTag:void 0;function Zn(e){return e==null?e===void 0?Jn:Xn:Bt&&Bt in Object(e)?Wn(e):Vn(e)}function er(e){return e!=null&&typeof e=="object"}var tr="[object Symbol]";function nr(e){return typeof e=="symbol"||er(e)&&Zn(e)==tr}var rr=/\s/;function or(e){for(var t=e.length;t--&&rr.test(e.charAt(t)););return t}var ar=/^\s+/;function sr(e){return e&&e.slice(0,or(e)+1).replace(ar,"")}function Qe(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Dt=NaN,ir=/^[-+]0x[0-9a-f]+$/i,cr=/^0b[01]+$/i,lr=/^0o[0-7]+$/i,ur=parseInt;function qt(e){if(typeof e=="number")return e;if(nr(e))return Dt;if(Qe(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Qe(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=sr(e);var n=cr.test(e);return n||lr.test(e)?ur(e.slice(2),n?2:8):ir.test(e)?Dt:+e}var Me=function(){return Mt.Date.now()},dr="Expected a function",hr=Math.max,_r=Math.min;function fr(e,t,n){var r,a,o,s,l,u,c=0,h=!1,i=!1,f=!0;if(typeof e!="function")throw new TypeError(dr);t=qt(t)||0,Qe(n)&&(h=!!n.leading,i="maxWait"in n,o=i?hr(qt(n.maxWait)||0,t):o,f="trailing"in n?!!n.trailing:f);function _(b){var g=r,H=a;return r=a=void 0,c=b,s=e.apply(H,g),s}function w(b){return c=b,l=setTimeout(m,t),h?_(b):s}function T(b){var g=b-u,H=b-c,U=t-g;return i?_r(U,o-H):U}function y(b){var g=b-u,H=b-c;return u===void 0||g>=t||g<0||i&&H>=o}function m(){var b=Me();if(y(b))return p(b);l=setTimeout(m,T(b))}function p(b){return l=void 0,f&&r?_(b):(r=a=void 0,s)}function k(){l!==void 0&&clearTimeout(l),c=0,r=u=a=l=void 0}function C(){return l===void 0?s:p(Me())}function I(){var b=Me(),g=y(b);if(r=arguments,a=this,u=b,g){if(l===void 0)return w(u);if(i)return clearTimeout(l),l=setTimeout(m,t),_(u)}return l===void 0&&(l=setTimeout(m,t)),s}return I.cancel=k,I.flush=C,I}function gr(e){const[t,n]=R(e.initialSuggestQuery),[r,a]=R(e.initialSearchQuery),[o,s]=R(e.initialLocale),[l,u]=R([]),[c,h]=R([]),[i,f]=R([]),[_,w]=R(!1),[T,y]=R(!1),[m,p]=R(!1),[k,C]=R(!1),[I,b]=R(""),g=fe(()=>Ae(o),[o]),[H,U]=R({message:g.statusInit,isError:!1}),$=F(!1),ee=F(0),Be=F(!1),De=F(!1),qe=F(!1),N=W(function(S){U(S),e.onStatusChange?.(S)},[e.onStatusChange]),Q=W(function(S){const L=S instanceof Error?S:new Error(g.statusError);e.onError?.(L),N({message:mr(L,g.statusError),isError:!0})},[e.onError,g.statusError,N]),te=W(async function(S="manual"){if(!qe.current){qe.current=!0,y(!0);try{const L=await e.api.hot({locale:o,limit:e.hotLimit,hours:e.hotHours});f(L),e.onHotContentsChange?.(L),S==="manual"&&N({message:g.statusHotRefreshed(L.length),isError:!1})}catch(L){S==="manual"&&Q(L)}finally{qe.current=!1,y(!1)}}},[Q,o,e.api,e.hotHours,e.hotLimit,e.onHotContentsChange,g,N]),je=W(async function(S,L="manual"){const A=(S??t).trim();if(!A){u([]),C(!1),e.onSuggestionsChange?.([]),L==="manual"&&N({message:g.statusSuggestNeedKeyword,isError:!0});return}if(De.current)return;const ye=ee.current+1;ee.current=ye,De.current=!0,p(!0),C(!0);try{const re=await e.api.suggest({query:A,limit:e.suggestLimit,locale:o});if(ye!==ee.current)return;u(re),e.onSuggestionsChange?.(re),L==="manual"&&N({message:g.statusSuggestRefreshed(re.length),isError:!1})}catch(re){if(ye!==ee.current)return;Q(re)}finally{ye===ee.current&&(De.current=!1,p(!1),C(!1))}},[Q,o,e.api,e.onSuggestionsChange,e.suggestLimit,t,g,N]),ne=fe(()=>fr(P=>{je(P,"auto")},e.debounceMs),[e.debounceMs,je]);G(()=>()=>ne.cancel(),[ne]);const Ge=W(async function(S){if(Be.current)return;const L=(S??t).trim();if(!L){N({message:g.statusSearchNeedKeyword,isError:!0});return}if(L.length<_e){N({message:`${g.statusSearchNeedKeyword} (min ${_e})`,isError:!0});return}Be.current=!0,w(!0),N({message:g.statusSearching,isError:!1});try{const A=await e.api.search({query:L,limit:e.searchLimit,locale:o});h(A),a(L),e.onResultsChange?.(A),N({message:g.statusSearchRefreshed(A.length),isError:!1})}catch(A){Q(A)}finally{Be.current=!1,w(!1)}},[Q,o,e.api,e.onResultsChange,e.searchLimit,t,g,N]),kr=W(async function(S){const L=r.trim();if(!L){N({message:g.statusTrackNeedSearch,isError:!0});return}b(S.id);try{const A={query:L,locale:o,contentId:S.id,contentTitle:S.title};S.locale&&(A.contentLocale=S.locale),await e.api.trackClick(A),N({message:g.statusClickRecorded(S.title),isError:!1}),await te("auto")}catch(A){Q(A)}finally{b("")}},[Q,r,o,e.api,te,g,N]);return G(function(){const S=t.trim();if(!S){u([]),C(!1),e.onSuggestionsChange?.([]),ne.cancel();return}C(!0),ne(S)},[ne,e.onSuggestionsChange,t]),G(function(){if(!e.autoSearchOnInit||$.current)return;const S=e.initialSearchQuery.trim();S&&($.current=!0,Ge(S))},[e.autoSearchOnInit,e.initialSearchQuery,Ge]),G(function(){if(!e.syncQueryToUrl)return;const S=_n(window.location.href,{suggestQuery:t,searchQuery:r}),L=`${window.location.pathname}${window.location.search}${window.location.hash}`;S!==L&&window.history.replaceState(null,"",S)},[r,e.syncQueryToUrl,t]),G(function(){te("auto")},[te]),{query:t,lastSearchQuery:r,locale:o,suggestions:l,results:c,hotContents:i,isSearching:_,isLoadingHot:T,isSuggesting:m,isSuggestPending:k,trackingId:I,status:H,setQuery:n,setLocale:s,runSearch:Ge,requestSuggestions:je,requestHotContents:te,trackResultClick:kr}}function mr(e,t){const n=e.message.trim();return!n||n.includes("{")||n.includes("}")||n.includes("[object")?t:n}function pr(e){const t=F(null),n=gr({api:e.api,suggestLimit:e.suggestLimit,searchLimit:e.searchLimit,hotLimit:e.hotLimit,hotHours:e.hotHours,debounceMs:e.debounceMs,syncQueryToUrl:e.syncQueryToUrl,autoSearchOnInit:e.autoSearchOnInit,initialLocale:e.initialLocale,initialSuggestQuery:e.initialSuggestQuery,initialSearchQuery:e.initialSearchQuery,...e.onStatusChange?{onStatusChange:e.onStatusChange}:{},...e.onSuggestionsChange?{onSuggestionsChange:e.onSuggestionsChange}:{},...e.onResultsChange?{onResultsChange:e.onResultsChange}:{},...e.onHotContentsChange?{onHotContentsChange:e.onHotContentsChange}:{},...e.onError?{onError:e.onError}:{}}),{hotContents:r,isLoadingHot:a,isSearching:o,isSuggestPending:s,isSuggesting:l,lastSearchQuery:u,locale:c,query:h,results:i,runSearch:f,setLocale:_,setQuery:w,status:T,suggestions:y}=n,m=Ae(c);G(function(){const I={search:f,setQuery:w,setLocale:_,getState(){return{query:h,locale:c,suggestions:y,results:i,hotContents:r,isSearching:o,isLoadingHot:a,isSuggesting:l,status:T}}};e.bindController(I)},[r,a,o,l,c,e.bindController,h,i,f,_,w,T,y]);const p=s||l,k=Qn(h,u);return d("section",{className:"asw-root",children:[d(An,{query:h,placeholder:e.placeholder,isSearching:o,clearQueryAriaLabel:m.clearQuery,searchButtonAriaLabel:m.refreshNormal,queryInputRef:t,onSearchSubmit:function(){f()},onQueryInput:function(I){w(I)},onClearQuery:function(){w(""),t.current?.focus()}}),T.isError&&d("p",{className:"asw-status is-error",children:T.message}),d("div",{className:"asw-content-area",children:[k==="hot"&&d(Nn,{hotContents:r,hotLimit:e.hotLimit,hotHours:e.hotHours,isLoadingHot:a,siteUrl:e.siteUrl,t:m}),k==="suggestion"&&d(Dn,{suggestions:y,isSuggestLoading:p,suggestLimit:e.suggestLimit,locale:c,siteUrl:e.siteUrl,t:m}),k==="search"&&d($n,{query:h,results:i,isSearching:o,locale:c,siteUrl:e.siteUrl,apiBaseUrl:e.api.apiBaseUrl,t:m})]})]})}const wr=[` .asw-root { --asw-bg: #ffffff; --asw-surface: #ffffff; --asw-border: #cccccc; --asw-soft-border: #e4e4e4; --asw-text: #333333; --asw-subtext: #555555; --asw-placeholder: #9b9b9b; --asw-accent: #009900; --asw-danger: #b42318; --asw-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); --asw-icon-fill: #555555; --asw-icon-hover: #009900; --asw-clear-hover-bg: rgba(0, 0, 0, 0.06); font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", Arial, sans-serif; color-scheme: light; color: var(--asw-text); border-radius: 8px; background: var(--asw-bg); padding: 10px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--asw-shadow); box-sizing: border-box; } @supports (-webkit-hyphens:none) { .asw-root { transform: translateY(-15rem); } } .asw-controls { display: flex; align-items: center; gap: 10px; width: 100%; } .asw-input-wrap { position: relative; flex-grow: 1; width: 100%; min-width: 0; } .asw-input { width: 100%; border: 2px solid var(--asw-border); border-radius: 5px; font: inherit; font-size: 18px; background: var(--asw-surface); color: var(--asw-text); outline: none; padding: 12px 44px 12px 15px; box-sizing: border-box; transition: border-color 0.2s ease; } .asw-input::placeholder { color: var(--asw-placeholder); } .asw-input:focus { border-color: var(--asw-accent); } .asw-input-clear-btn { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border: none; border-radius: 50%; background: transparent; color: var(--asw-subtext); cursor: pointer; padding: 0; } .asw-input-clear-btn:hover { color: var(--asw-text); background: var(--asw-clear-hover-bg); } .asw-input-clear-btn svg { width: 16px; height: 16px; display: block; fill: currentColor; } .asw-search-icon-btn { border: none; background: transparent; padding: 5px; cursor: pointer; display: flex; align-items: center; justify-content: center; } .asw-search-icon-btn svg { width: 28px; height: 28px; display: block; } .asw-search-icon-btn svg path { fill: var(--asw-icon-fill); transition: fill 0.2s ease-in-out; } .asw-search-icon-btn:hover:not(:disabled) svg path { fill: var(--asw-icon-hover); } .asw-search-icon-btn:disabled { opacity: 0.6; cursor: not-allowed; } .asw-status { margin: 0; font-size: 13px; color: var(--asw-subtext); } .asw-status.is-error { color: var(--asw-danger); } .asw-panel { display: flex; flex-direction: column; gap: 6px; } .asw-panel h3 { margin: 0; font-size: 14px; color: var(--asw-subtext); padding: 0 4px; } .asw-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; min-width: 0; } .asw-empty { padding: 10px; border: 1px dashed var(--asw-soft-border); border-radius: 5px; color: var(--asw-subtext); font-size: 13px; background: var(--asw-surface); min-height: 40px; box-sizing: border-box; display: flex; align-items: center; } `,` .asw-suggestion { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left; padding: 8px 10px; border: 1px solid var(--asw-soft-border); border-radius: 5px; background: var(--asw-surface); color: var(--asw-text); cursor: pointer; box-sizing: border-box; overflow: hidden; text-decoration: none; min-height: 40px; transition: border-color 0.2s ease, color 0.2s ease; } .asw-suggestion:visited { color: var(--asw-text); } .asw-suggestion:hover { border-color: var(--asw-accent); color: var(--asw-accent); } .asw-static-item { cursor: default; } .asw-static-item:hover { border-color: var(--asw-soft-border); color: var(--asw-text); } .asw-suggestion-link { display: flex; align-items: center; } .asw-suggestion-static { display: flex; align-items: center; } .asw-suggestion-text { width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.25; } .asw-suggestion-list { align-content: start; } .asw-suggestion-skeleton { pointer-events: none; justify-content: flex-start; } .asw-suggestion-skeleton .asw-skeleton-line { width: min(86%, 340px); } .asw-suggestion-padding { border-color: transparent; background: transparent; pointer-events: none; } .asw-hot-link { display: flex; align-items: center; justify-content: space-between; gap: 10px; text-decoration: none; } .asw-hot-list { align-content: start; } .asw-hot-title { flex: 1; min-width: 0; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .asw-hot-meta { display: inline-block; margin-left: 8px; font-size: 12px; color: var(--asw-subtext); white-space: nowrap; } .asw-hot-skeleton { pointer-events: none; } .asw-skeleton-line, .asw-skeleton-meta { display: inline-block; border-radius: 999px; background: var(--asw-soft-border); animation: asw-pulse 1.6s ease-in-out infinite; } .asw-skeleton-line { width: min(72%, 280px); height: 14px; } .asw-skeleton-meta { width: 42px; height: 12px; flex-shrink: 0; } `,` .asw-result { border: 1px solid var(--asw-soft-border); border-radius: 5px; padding: 10px; display: grid; gap: 6px; background: var(--asw-surface); } .asw-result-link { display: block; color: inherit; text-decoration: none; } .asw-title { margin: 0; font-size: 15px; font-weight: 700; color: var(--asw-text); line-height: 1.35; overflow-wrap: anywhere; } .asw-content { margin: 0; color: var(--asw-subtext); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; } .asw-meta { margin: 0; color: var(--asw-accent); font-size: 12px; font-weight: 600; } .asw-track { justify-self: start; border: 1px solid var(--asw-soft-border); border-radius: 5px; padding: 6px 10px; background: var(--asw-surface); color: var(--asw-subtext); cursor: pointer; transition: border-color 0.2s ease, color 0.2s ease; } .asw-track:hover:not(:disabled) { border-color: var(--asw-accent); color: var(--asw-accent); } .asw-track:disabled { opacity: 0.65; cursor: not-allowed; } .asw-search-panel { transform-origin: top center; animation: asw-panel-pop 220ms cubic-bezier(0.19, 1, 0.22, 1); } .asw-loading-indicator { font-size: 0.8em; color: var(--asw-subtext); margin-left: 8px; animation: asw-pulse 1.5s infinite; } @keyframes asw-panel-pop { 0% { opacity: 0; transform: translateY(8px) scale(0.985); } 70% { opacity: 1; transform: translateY(0) scale(1.005); } 100% { opacity: 1; transform: translateY(0) scale(1); } } @keyframes asw-pulse { 0% { opacity: 0.3; } 50% { opacity: 1; } 100% { opacity: 0.3; } } .asw-spinner { width: 100%; height: 100%; transform-origin: center; animation: asw-spin 2s linear infinite; } @keyframes asw-spin { 100% { transform: rotate(360deg); } } `,` @media (prefers-color-scheme: dark) { .asw-root { --asw-bg: #11161b; --asw-surface: #1b232b; --asw-border: #3b4754; --asw-soft-border: #2c3642; --asw-text: #edf2f7; --asw-subtext: #b9c5d1; --asw-placeholder: #8694a3; --asw-accent: #3cc96b; --asw-danger: #f97066; --asw-shadow: 0 12px 28px rgba(0, 0, 0, 0.5); --asw-icon-fill: #b9c5d1; --asw-icon-hover: #3cc96b; --asw-clear-hover-bg: rgba(255, 255, 255, 0.12); color-scheme: dark; } .asw-dialog::backdrop { background: rgba(0, 0, 0, 0.62); } } @media (prefers-reduced-motion: reduce) { .asw-search-panel { animation: none; } } @media (max-width: 768px) { .asw-input { font-size: 16px; padding: 10px 40px 10px 12px; } .asw-search-icon-btn svg { width: 26px; height: 26px; } .asw-panel h3 { font-size: 13px; } .asw-suggestion { font-size: 13px; padding: 7px 9px; } .asw-title { font-size: 14px; } .asw-content { font-size: 12px; } .asw-hot-meta { font-size: 11px; } } @media (max-width: 640px) { .asw-input { font-size: 14px; padding: 8px 36px 8px 10px; } .asw-search-icon-btn { padding: 3px; } .asw-search-icon-btn svg { width: 22px; height: 22px; } .asw-input-clear-btn { right: 8px; } .asw-input-clear-btn svg { width: 14px; height: 14px; } } `,` .asw-dialog { border: none; background: transparent; padding: 0; width: 90%; max-width: 600px; max-height: 90vh; margin: auto; overflow: visible; outline: none; } .asw-dialog::backdrop { background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); } .asw-dialog-close { position: absolute; right: 0; top: -40px; background: transparent; border: none; color: #fff; font-size: 28px; cursor: pointer; line-height: 1; padding: 5px; } .asw-dialog-close:hover { opacity: 0.8; } .asw-dialog-inner { position: relative; width: 100%; height: 100%; } .asw-content-area { overflow-y: auto; overflow-x: hidden; max-height: calc(90vh - 80px); /* 减去搜索框等头部的高度 */ } `];function yr(){return` ${wr.join(` `)} `}const jt="arealme-search-widget-style",br=yr();function Sr(e){if(e.getElementById(jt))return;const t=e.createElement("style");t.id=jt,t.textContent=br,e.head.appendChild(t)}function ze(e){const t=vr(e);Sr(document);const n={apiBaseUrl:t.apiBaseUrl};e.requestTimeoutMs!==void 0&&(n.requestTimeoutMs=e.requestTimeoutMs);const r=St(n);let a=null;return st(d(pr,{api:r,siteUrl:t.siteUrl,localeOptions:e.localeOptions??nn,initialLocale:t.locale,suggestLimit:t.suggestLimit,searchLimit:t.searchLimit,hotLimit:t.hotLimit,hotHours:t.hotHours,debounceMs:t.debounceMs,placeholder:t.placeholder,syncQueryToUrl:t.syncQueryToUrl,autoSearchOnInit:t.autoSearchOnInit,initialSuggestQuery:t.initialSuggestQuery,initialSearchQuery:t.initialSearchQuery,bindController:function(s){a=s},...e.onStatusChange?{onStatusChange:e.onStatusChange}:{},...e.onSuggestionsChange?{onSuggestionsChange:e.onSuggestionsChange}:{},...e.onResultsChange?{onResultsChange:e.onResultsChange}:{},...e.onHotContentsChange?{onHotContentsChange:e.onHotContentsChange}:{},...e.onError?{onError:e.onError}:{}}),t.mountElement),{destroy(){st(null,t.mountElement),a=null},search(o){return we(a).search(o)},setQuery(o){we(a).setQuery(o)},setLocale(o){we(a).setLocale(o)},getState(){return we(a).getState()}}}function we(e){if(!e)throw new Error("search widget 尚未初始化完成");return e}function vr(e){const t=Tr(e.mount),n=e.apiBaseUrl?.trim()||"https://search.arealme.net",r=Cr(e.siteUrl),a=xr(e.locale),o=Z(e.suggestLimit,ut),s=Z(e.searchLimit,dt),l=Z(e.hotLimit,Ee),u=Z(e.hotHours,ke),c=Z(e.debounceMs,en),h=Ae(a),i=e.placeholder?.trim()||h.placeholder,f=e.syncQueryToUrl===!0,_=e.autoSearchOnInit!==!1,w=f?hn(window.location.href):{suggestQuery:"",searchQuery:""},T=e.initialQuery?.trim()||w.suggestQuery||w.searchQuery,y=e.initialSearchQuery?.trim()||w.searchQuery;return{mountElement:t,apiBaseUrl:n,siteUrl:r,locale:a,suggestLimit:o,searchLimit:s,hotLimit:l,hotHours:u,debounceMs:c,placeholder:i,syncQueryToUrl:f,autoSearchOnInit:_,initialSuggestQuery:T,initialSearchQuery:y}}function Tr(e){if(typeof e=="string"){const t=document.querySelector(e);if(!t)throw new Error(`未找到挂载节点:${e}`);return t}return e}function xr(e){const t=e?.trim().toLowerCase();return t||it}function Z(e,t){if(e===void 0)return t;const n=Math.trunc(e);return!Number.isFinite(n)||n<=0?t:n}function Cr(e){const t=e?.trim()||lt;try{return ft(t)}catch{return lt}}const Lr='';function Gt(){const e=document.getElementById("arm_toolset"),t=document.getElementById("arm_topnav_mybar");if(!e||!t)return;const n=document.createElement("i");n.id="arm_search",n.innerHTML=Lr,e.insertBefore(n,t);const r=e.dataset;let a=null;function o(){if(!a){a=document.createElement("dialog"),a.className="asw-dialog";const s=document.createElement("button");s.className="asw-dialog-close",s.type="button",s.innerHTML="×",s.onclick=()=>a?.close();const l=document.createElement("div");l.className="asw-dialog-inner";const u=document.createElement("div");l.appendChild(u),a.appendChild(s),a.appendChild(l),document.body.appendChild(a),a.addEventListener("click",f=>{f.target===a&&a?.close()});let c=r.locale;if(!c){const f=window.location.pathname.split("/").filter(Boolean).pop();f&&(c=f)}const h={mount:u};r.apiBaseUrl&&(h.apiBaseUrl=r.apiBaseUrl),r.siteUrl&&(h.siteUrl=r.siteUrl),c&&(h.locale=c),r.suggestLimit&&(h.suggestLimit=parseInt(r.suggestLimit,10)),r.searchLimit&&(h.searchLimit=parseInt(r.searchLimit,10)),r.hotLimit&&(h.hotLimit=parseInt(r.hotLimit,10)),r.hotHours&&(h.hotHours=parseInt(r.hotHours,10));const i=Er(r.syncQueryToUrl);i!==void 0&&(h.syncQueryToUrl=i),ze(h)}a.showModal()}n.addEventListener("click",o)}function Er(e){if(e===void 0)return;const t=e.trim().toLowerCase();if(["1","true","yes","on"].includes(t))return!0;if(["0","false","no","off"].includes(t))return!1}return typeof window<"u"&&(window.ArealmeSearchWidget={mount:ze},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Gt):Gt()),oe.createSearchApi=St,oe.mountSearchWidget=ze,Object.defineProperty(oe,Symbol.toStringTag,{value:"Module"}),oe})({});